home *** CD-ROM | disk | FTP | other *** search
/ Pascal Super Library / Pascal Super Library (CW International)(1997).bin / LIBRARY / PAS_0493 / OS_TEST.PAS < prev    next >
Pascal/Delphi Source File  |  1993-04-15  |  5KB  |  148 lines

  1. {─ Fido Pascal Conference ────────────────────────────────────────────── PASCAL ─
  2. Msg  : 224 of 231
  3. From : Gregory P. Smith                    1:104/332.11         12 Apr 93  17:21
  4. To   : Tim Strike                          1:259/423.0
  5. Subj : Detect OS/2 and WINDOWS sessions
  6. ────────────────────────────────────────────────────────────────────────────────
  7. On Apr 07 07:08, Tim Strike of 1:259/423 wrote:
  8.  
  9.  TS> Is there any way to detect OS/2 (in a DOS box) sessions and Windows
  10.  TS> Sessions? I'd like to throw in support for these multitaskers so I can
  11.  TS> run an idlekey program.
  12.  
  13. Actual code is always the best example for me..  Look at this unit (and use it,
  14. I think you'll like it).  Check with someone else if you want to specifically
  15. detect winslows.  This unit will, however, give up time to any multitasker.
  16.  
  17. ===================== }
  18.  
  19. (* Public Domain unit by Gregory P. Smith, No Rights Reserved *)
  20. (* ...  This also means no guarantees  ... *)
  21. Unit OS_Test; { DESQview, OS/2, & 386 v86 machine interfaces }
  22. {$X+,S-,R-,F-,O-,D-,G-} { extended syntax, nothing else }
  23. interface
  24.  
  25. const
  26.   In_DV  : boolean = False; { are we in DESQview? }
  27.   In_VM  : boolean = False; { are we in a 386+ virtual machine? }
  28.   In_OS2 : boolean = False; { are we in OS/2? }
  29.  
  30. function  OS2_GetVersion: word; { Get OS/2 version # }
  31. Function  DV_GetVersion: word; { update In_DV and get version # }
  32. Function  DV_Get_Video_Buffer(vseg:word): word; { get the alt video buffer }
  33. Procedure DV_Pause; { give up time slice }
  34. Procedure MT_Pause; Inline($cd/$28); { give up time in most multitaskers }
  35. Procedure KillTime; { Release time in any situation }
  36. Procedure DV_Begin_Critical; { don't slice away }
  37.   Inline($b8/$1b/$10/$cd/$15);
  38. Procedure DV_End_Critical; { allow slicing again }
  39.   Inline($b8/$1c/$10/$cd/$15);
  40. Procedure DV_Sound(freq,dur:integer); { Create a sound in the Bkg }
  41.  
  42. implementation
  43.  
  44. function OS2_GetVersion: word; assembler;
  45. asm
  46.   MOV    AH, 30h  { DOS Get Version Call }
  47.   INT    21h      { AL = major version * 10, AH = minor version }
  48.   MOV    BH, AH   { save minor version }
  49.   XOR    AH, AH
  50.   MOV    CL, 10
  51.   DIV    CL       { divide by 10 to get the major version }
  52.   MOV    AH, BH   { restore minor version }
  53.   XCHG   AH, AL   { AH = major, AL = minor }
  54. end;
  55.  
  56. Function DV_GetVersion: word; assembler;
  57. asm
  58.   MOV    CX,'DE'     { CX+DX to 'DESQ' (invalid date) }
  59.   MOV    DX,'SQ'
  60.   MOV    AX,02B01H   { Dos' set date funct. }
  61.   INT    21H         { call dos }
  62.   CMP    AL,0FFH     { Was it invalid? }
  63.   JE     @No_dv      { yep, no dv }
  64.   MOV    AX,BX       { AH=major AL=minor }
  65.   MOV    In_DV,1     { Set In_DV flag }
  66.   JMP    @DvGv_x     { other routines }
  67. @No_dv:
  68.   XOR    AX,AX       { Return 0 or no DV }
  69. @DvGv_x:
  70. end; { DV_GetVersion }
  71.  
  72. Function DV_Get_Video_Buffer(vseg:word): word; assembler;
  73. asm                      { Modified by Scott Samet April 1992 }
  74.   CALL   DV_GetVersion   { Returns AX=0 if not in DV }
  75.   MOV    ES,vseg         { Put current segment into ES }
  76.   TEST   AX,AX           { In DV? }
  77.   JZ     @DVGVB_X        { Jump if not }
  78.   MOV    AH,0FEH         { DV's get video buffer function }
  79.   INT    10H             { Returns ES:DI of alt buffer }
  80. @DVGVB_X:
  81.   MOV    AX,ES           { Return video buffer }
  82. end; { DV_Get_Video_Buffer }
  83.  
  84. Procedure DV_Pause;
  85. begin
  86.   if In_DV then
  87.    asm
  88.      MOV AX, 1000h    { pause function }
  89.      INT 15h
  90.    end;
  91. end; { DV_Pause }
  92.  
  93. Procedure KillTime;
  94. begin
  95.   if In_VM then
  96.    asm
  97.      MOV AX, 1680h    { give up VM time slice }
  98.      INT 2Fh
  99.    end
  100.   else if In_DV then
  101.    asm
  102.      MOV AX, 1000h    { DV pause call }
  103.      INT 15h
  104.    end
  105.   else MT_Pause;      { DOS Idle call }
  106. end;
  107.  
  108. (* Procedure DV_Begin_Critical; assembler;
  109. asm
  110.   MOV AX,$101B       { DV begin critical function }
  111.   INT 15h
  112. end; { DV_Begin_Critical }
  113.  
  114. Procedure DV_End_Critical; assembler;
  115. asm
  116.   MOV AX,$101C       { DV end critical function }
  117.   INT 15h
  118. end; { DV_End_Critical }  *)
  119.  
  120. Procedure DV_Sound(freq,dur:integer); assembler; { sound a tone }
  121. asm
  122.   MOV   AX,1019H
  123.   MOV   BX,freq  { frequency above 20 Hz }
  124.   MOV   CX,dur   { duration in clock ticks }
  125.   INT   15H
  126. end;
  127.  
  128. { ** -- initalization -- ** }
  129.  
  130. BEGIN
  131.   DV_GetVersion; { discard answer.  Just update In_DV }
  132.   asm
  133.     MOV AX, 1680h
  134.     INT 2Fh          { Gives up time slice in most 386+ virtual machines }
  135.     NOT AL           { AL = 00h if supported, remains 80h if not }
  136.     MOV CL, 7
  137.     SHR AL, CL       { move bit 7 to bit 0 for a boolean }
  138.     MOV In_VM, AL    { update the flag }
  139.   end;
  140.   In_OS2 := (OS2_GetVersion >= $0100); { version 1.0 or greater }
  141. END.
  142.  
  143.  .. Greg
  144.  
  145. --- msgedsq/2 2.2b
  146.  * Origin: Greg's Pascal with OS/2 & pickles point (1:104/332.11)
  147.  
  148.